//
//  BIZConsultorImagesTabCell.m
//  biz
//
//  Created by zhangfuwei on 2017/4/11.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZConsultorImagesTabCell.h"
#import "BIZConsultorDetailModel.h"

@interface BIZConsultorImagesTabCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
/** 左上角图片 */
@property (nonatomic, strong)     UIImageView *iconImgV;
/** 标题 */
@property (nonatomic, strong)     UILabel     *titleLabel;
/** 更多 */
@property (nonatomic, strong)     UILabel    *moreLabel;
/** 风采图 */
@property (nonatomic, strong)     UIImageView *imageImgV;
/** 风采滚动图 */
@property (nonatomic, strong) UICollectionView *collectionView;
/** 风采图集合 */
@property (nonatomic, strong) NSArray *styleArr;

@end

@implementation BIZConsultorImagesTabCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self loadUI];
        self.styleArr = [NSArray array];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

- (void)loadUI {
    
    _iconImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"consultor_cup"]];
    _titleLabel = [[UILabel alloc] init];
    _moreLabel = [[UILabel alloc] init];
    
    _titleLabel.text = @"咨询师风采";
//    _moreLabel.text = @"更多";
    
    [self.contentView addSubview:_iconImgV];
    [self.contentView addSubview:_titleLabel];
//    [self.contentView addSubview:_moreLabel];
    
    
    [_iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.top.equalTo(self.contentView).offset(8);
        make.width.height.equalTo(@25);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconImgV.mas_right).offset(10);
        make.top.equalTo(self.contentView).offset(10);
        make.height.equalTo(@20);
    }];
    
//    [_moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.contentView).offset(-10);
//        make.top.equalTo(_titleLabel);
//        make.height.equalTo(@20);
//    }];
    
    [self.contentView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(20);
        make.bottom.equalTo(self.contentView).offset(-10);
        make.left.right.equalTo(self.contentView);
        make.height.equalTo(@65);
    }];
}

-(void)setDetailM:(BIZConsultorDetailModel *)detailM {
    _detailM = detailM;
//    NSArray *arr = @[@"A2AoXWsl1_1495418581783",@"ISxvlPJD1_1495156596117",@"rKBHSeXU1_1495156596102"];
    //    self.styleArr =  [self.styleArr arrayByAddingObjectsFromArray:arr];
    self.styleArr = [_detailM.style componentsSeparatedByString:@","];
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.styleArr.count?:1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseCell" forIndexPath:indexPath];
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (Main_Screen_Width-60)/3.0,65)];
    [cell.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DeLog(@"leixing--%@",obj.class);
    }];
    [SDWebImageTool imageView:imgV imageName:self.styleArr[indexPath.row] placeHolder:@"defaultStyle" showProgress:YES];
    
    [cell.contentView addSubview:imgV];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake((Main_Screen_Width-15*3)/3.0,65);
        layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
        layout.minimumInteritemSpacing = 15;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
        
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseCell"];
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.scrollEnabled = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
    }
    return _collectionView;
}


@end
